package com.sddfp.system.controller;

import com.sddfp.common.model.dto.CardBindDto;
import com.sddfp.common.model.dto.LoginDto;
import com.sddfp.common.model.dto.SignatureDto;
import com.sddfp.common.model.dto.UserRegisterDto;
import com.sddfp.common.model.vo.LoginVo;
import com.sddfp.common.result.Result;
import com.sddfp.system.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hzk
 * @since 2025-08-25
 */
@RestController
@RequestMapping("/user")
@Api("用户接口")
@Slf4j
public class UserController {

    private final IUserService userService;

    public UserController(IUserService userService){
        this.userService = userService;
    }


    @PostMapping("/regist")
    @ApiOperation("用户注册")
    public Result regist(@RequestBody @Valid UserRegisterDto userRegisterDto){
        log.info("用户注册请求参数：{}",userRegisterDto);
        userService.regist(userRegisterDto);
        return Result.ok();
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result login(@RequestBody LoginDto loginDto){
        LoginVo loginVo = userService.login(loginDto);
        return Result.ok(loginVo);
    }

    /**
     * 用户绑卡
     * 系统1：当前管理系统提供接口：addBankAccount
     * 系统2：托管代理系统，提供接口：proxyBindCardLog，进行绑卡日志的记录
     */
    @PostMapping("/bank/card/add")
    public Result<SignatureDto> addBankAccount(@RequestBody CardBindDto cardBindDto){
        SignatureDto signatureDto = userService.addBankAccount(cardBindDto);
        return Result.ok(signatureDto);
    }

}
